# -*- coding:UTF-8 -*-
from cmdb.models import SystemInfo

def system_info(start,end):
    systemRes = SystemInfo.objects.all()

def add_system_info(equipment_no, system_ver, core_ver, sys_parent_ip, use_status, comment, operator, cursor):
    system_sql = 'insert into system_info set equipment_no="' + equipment_no + '",system_ver="' + system_ver \
                     + '",core_ver="' + core_ver + '",sys_parent_ip="' + sys_parent_ip + '",use_status=' + str(use_status) \
                     + ',comment="' + comment + '",operator="' + operator +'"'
    cursor.execute(system_sql)

def update_system_info(equipment_no, system_ver, core_ver, sys_parent_ip, use_status, comment, operator, cursor):
    sys_update_sql = 'update system_info set system_ver="' + system_ver+ '",core_ver="' + core_ver \
                     + '",sys_parent_ip="' + sys_parent_ip + '",use_status=' + str(use_status) + ',comment="' \
                     + comment + '",operator="' + operator + '"'\
                     + ' where equipment_no="' + equipment_no + '"'
    cursor.execute(sys_update_sql)


def get_system_info(equipment_no):
    sysRes = SystemInfo.objects.get(equipment_no=equipment_no)
    return sysRes

def del_system_info(equipment_no, cursor):
    system_del = 'delete from system_info where equipment_no="' + equipment_no + '"'
    cursor.execute(system_del)

def update_status_system_info(equipment_no,use_status,cursor):
    system_update = 'update system_info set use_status = ' + use_status + ' where equipment_no="' + equipment_no + '"'
    print system_update
    cursor.execute(system_update)